﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using CoolERP_BLL;
using CoolERP_Entities;

namespace CoolERP_Web.User
{
    public partial class SelectYSKZD : BasePage
    {
        private Guid KHID
        {
            get { return this.GetUrlParam("id") == null ? Guid.Empty : new Guid(this.GetUrlParam("id").ToString()); }
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                BindFirst();
                BindData();
            }
        }

        private void BindFirst()
        {
            //if (this.GetUrlParam("id") != null)
            //    hidSelIds.Value = this.GetUrlParam("ids").ToString();

            this.AspNetPager1.PageSize = GridView1.PageSize;
        }

        protected void btnQuery_Click(object sender, ImageClickEventArgs e)
        {
            this.AspNetPager1.CurrentPageIndex = 1;
            BindData();
        }

        private void BindData()
        {
            //Dictionary<string, string> dc = new Dictionary<string, string>();
            //if (!string.IsNullOrEmpty(txtName.Text.Trim()))
            //    dc.Add("CPMC", txtName.Text.Trim());
            //if (!string.IsNullOrEmpty(ddlType.SelectedValue))
            //    dc.Add("CPLX", ddlType.SelectedValue);
            //if (!string.IsNullOrEmpty(ddlHXC.SelectedValue))
            //    dc.Add("CPHXC", ddlHXC.SelectedValue);

            //using (ZL_CPBLL cBLL = new ZL_CPBLL())
            //{
            //    int RecordCount = 0;
            //    List<vCP> itemLists = cBLL.GetCP(dc, "BH", this.AspNetPager1.CurrentPageIndex, this.AspNetPager1.PageSize, out RecordCount);
            //    this.AspNetPager1.RecordCount = RecordCount;
            //    GridView1.DataSource = itemLists;
            //    GridView1.DataBind();
            //    this.AspNetPager1.Visible = RecordCount > 0;
            //    panMsg.Visible = !this.AspNetPager1.Visible;
            //}
            int i = 0;
            Dictionary<string, string> dc = new Dictionary<string, string>();
            dc.Add("ZDZT", i.ToString());
            if (!string.IsNullOrEmpty(tbCZRYName.Text.Trim()))
                dc.Add("CZRYName", tbCZRYName.Text.Trim());
            if (!string.IsNullOrEmpty(tbCJSJ.Text.Trim()))
                dc.Add("CJSJ", tbCJSJ.Text.Trim());
            if (!string.IsNullOrEmpty(tbCKSJ.Text.Trim()))
                dc.Add("CKSJ", tbCKSJ.Text.Trim());
            if (!string.IsNullOrEmpty(tbYSZEMin.Text.Trim()))
                dc.Add("YSZEMin", tbYSZEMin.Text.Trim());
            if (!string.IsNullOrEmpty(tbYSZEMax.Text.Trim()))
                dc.Add("YSZEMax", tbYSZEMax.Text.Trim());
            using (CW_YSKZDBLL yskzdB = new CW_YSKZDBLL())
            {
                if (KHID!=Guid.Empty)
                {
                    dc.Add("KHID", KHID.ToString());
                }
                int RecordCount = 0;
                List<YSKZDModel> itemLists = yskzdB.GetYSKZD(dc, "BH", this.AspNetPager1.CurrentPageIndex, this.AspNetPager1.PageSize, out RecordCount);
                this.AspNetPager1.RecordCount = RecordCount;
                GridView1.DataSource = itemLists;
                GridView1.DataBind();
                this.AspNetPager1.Visible = RecordCount > 0;
                panMsg.Visible = !this.AspNetPager1.Visible;
            }

        }

        protected void AspNetPager1_PageChanged(object sender, EventArgs e)
        {
            BindData();
        }
    }
}